package com.reminiscence.classes;

import java.io.Serializable;
import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;

import com.reminiscence.database.OperazioniDB;
import com.reminiscence.main.MainActivity;

public class Storia implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7779767860872922142L;

	
	public Integer idStoria;
	public String titolo;
	public String testo;
	public String data;
	public String dataPub;
	public String anno;
	public String nomeUtenteEs;
	public Integer latEs;
	public Integer lonEs;
	public String luogo;
	
	
	private ArrayList<NameValuePair> params;
	
	public static Boolean leggiStoria(Activity activity, int ids)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		
		params.add(new BasicNameValuePair("IdStoria", Integer.toString(ids)));
		
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "leggiStoria", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
	
	public Boolean inserisciStoria(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		//params.add(new BasicNameValuePair("IdStoria", this.idStoria.toString()));
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtenteEs));
		params.add(new BasicNameValuePair("Titolo", this.titolo));
		params.add(new BasicNameValuePair("Testo", this.testo));
		params.add(new BasicNameValuePair("Anno", this.anno.toString()));
		params.add(new BasicNameValuePair("Luogo", this.luogo));
		
		
		
		try
		{
			ret = (Boolean)(new OperazioniDB(activity, "inserisciStoria", params).execute().get());
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return ret;
	}
	
	public Boolean eliminaStoria(Activity activity, String idS)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		
		params.add(new BasicNameValuePair("IdStoria", idS));
		params.add(new BasicNameValuePair("IdUtente", MainActivity.utente.nomeUtente));
		
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "eliminaStoria", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
	
	public Boolean modificaStoria(Activity activity, String idS)
	{
	Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		
		params.add(new BasicNameValuePair("IdStoria", idS));
		params.add(new BasicNameValuePair("IdUtente", MainActivity.utente.nomeUtente));
		params.add(new BasicNameValuePair("Testo", MainActivity.storia.testo));
		params.add(new BasicNameValuePair("Titolo", MainActivity.storia.titolo));
		params.add(new BasicNameValuePair("Anno", MainActivity.storia.anno));
		params.add(new BasicNameValuePair("Luogo", MainActivity.storia.luogo));

		
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "modificaStoria", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
}
